{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2019-04-24 23:43:20.786511 1556120600786 1558712600786\n"
     ]
    }
   ],
   "source": [
    "# 完整时间的毫秒时间戳\n",
    "import datetime\n",
    "import time\n",
    "\n",
    "# 将时间段转换为日期\n",
    "days = 30\n",
    "intervalDays = datetime.timedelta(days=30)\n",
    "startDay = (datetime.datetime.now()- intervalDays)\n",
    "t = int((time.mktime(startDay.timetuple()) + startDay.microsecond / 1E6)*1000)\n",
    "endTime = int((time.mktime(datetime.datetime.now().timetuple()) + startDay.microsecond / 1E6)*1000)\n",
    "print(startDay,t,endTime)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1543977561.6497624\n",
      "1543977561\n",
      "1543977561650\n",
      "1543977561650\n",
      "2018-12-05 10:39:21\n"
     ]
    }
   ],
   "source": [
    "# 仅年月日的时间戳\n",
    "import time\n",
    "import datetime\n",
    "intervalDays = datetime.timedelta(days=30)\n",
    "startDay = (datetime.datetime.now()- days)\n",
    "\n",
    "t = time.time()\n",
    "print (t)                       #原始时间数据\n",
    "print (int(t))                  #秒级时间戳\n",
    "print (int(round(t * 1000)))    #毫秒级时间戳\n",
    "\n",
    "nowTime = lambda:int(round(t * 1000))\n",
    "print (nowTime());              #毫秒级时间戳，基于lambda\n",
    "\n",
    "print (datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))   #日期格式化\n",
    "ts = int(time.mktime(time.strptime(startDay, \"%Y-%m-%d\")))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import datetime\n",
    "# min = datetime.datetime.minute(datetime.datetime.now())\n",
    "currentTime = datetime.datetime.now() \n",
    "currentTime.minute\n",
    "# date = datetime.datetime.minute(currentTime)\n",
    "# # date.days\n",
    "# print(date)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 时间戳转换为指定格式日期:\n",
    "# 方法一:\n",
    "# 利用localtime()转换为时间数组,然后格式化为需要的格式,如\n",
    "import time\n",
    "timeStamp = 1542018934\n",
    "timeArray = time.localtime(timeStamp)\n",
    "otherStyleTime = time.strftime(\"%Y-%m-%d %H:%M:%S\", timeArray)\n",
    "otherStyleTime "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2019, 5, 24, 23, 43, 26, 56294)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.datetime.today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
